package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.CustomerVisitingCost;


public interface CustomerVisitingCostRepository extends JpaRepository<CustomerVisitingCost, String> {
	/// 来访费用查询
	@Query(" select k from CustomerVisitingCost k where k.customerVisiting.id=?1 and k.costName like '%'+?2+'%' ")
	Page<CustomerVisitingCost> findVisitCost(String id,String key, Pageable pageable);
	
	@Query(" select k from CustomerVisitingCost k where k.customerVisiting.id=?1")
	Page<CustomerVisitingCost> findVisitCost(String id,Pageable pageable);
	
	//来访费用查询条数
	@Query(" select count(k) from CustomerVisitingCost k where k.customerVisiting.id=?1 and k.costName like '%'+?2+'%' ")
	Long getCount(String id,String key);
	
	@Query(" select count(k) from CustomerVisitingCost k where k.customerVisiting.id=?1")
	Long getCount(String id);
	
   //删除与来访相关的费用visitId
	@Transactional
	@Modifying  
	@Query("delete from CustomerVisitingCost k where k.customerVisiting.id=?1 ")
	public void deleteCost(String visitId);
	


}
